package org.erp.product.strategy.impl;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.annotation.StockLockBatch;
import org.erp.common.constant.ProductConstant;
import org.erp.common.enums.DeviceInventoryEvent;
import org.erp.product.domain.entity.ConnectLog;
import org.erp.product.infrastructure.enums.ConnectEventEnum;
import org.erp.product.service.ConnectLogService;
import org.erp.product.strategy.ConnectActionStrategy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Log4j2
@Service(value = "QUASH")
@AllArgsConstructor
public class QuashConnectActionStrategy implements ConnectActionStrategy {

    private ConnectLogService connectLogService;

    @StockLockBatch(directIds = true, busyKey = ProductConstant.PRODUCT_BUSY_CONNECT_LOGS)
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void execute(List<Long> ids) {
        List<ConnectLog> connectLogList = connectLogService.searchAndVerify(ids, ConnectEventEnum.QUASH);
        connectLogService.handleWarehouse(connectLogList, DeviceInventoryEvent.CANCEL_REJECT);
    }
}
